import {FC} from "react";
import {Rate, RateProps} from "antd";
import {setBookScore} from "@/apis/book";
import {ApiConstants} from "@/apis/constants";
import {errorMessage, successMessage} from "@/common/components/Message";

interface Props extends RateProps {
    id: string
}

export const Store: FC<Props> = (props) => {
    const {id} = props
    function setScore(val: number) {
        setBookScore(id, val * 2).then(({code, msg}) => {
            if (code === ApiConstants.SUCCESS) {
                successMessage("评分成功")
            } else {
                errorMessage(msg)
            }
        })

    }

    return (
        <Rate allowHalf {...props} onChange={setScore}/>
    )
}
